package bb.lanxing.adapter.team;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

import bb.lanxing.model.data.TeamImageData;

public class TeamDetailBannerAdapter extends BannerAdapter<TeamImageData, TeamDetailBannerAdapter.BannerViewHolder> {
    private Context mContext;

    public TeamDetailBannerAdapter(List<TeamImageData> list) {
        super(list);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        ImageView imageView = new ImageView(parent.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(BannerViewHolder holder, TeamImageData data, int position, int size) {
        if (data.type == 0) {
            holder.imageView.setImageResource(data.imageResource);
        } else {
            Glide.with(mContext).load(data.imageUrl).into(holder.imageView);
        }
    }

    class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public BannerViewHolder(@NonNull ImageView view) {
            super(view);
            imageView = view;
        }
    }
}